package com.guxingke.typecho4j.widget.provider.option;

import com.guxingke.typecho4j.Typecho4jException;
import com.guxingke.typecho4j.jfinal.model.Comment;
import com.guxingke.typecho4j.jfinal.model.Content;
import com.guxingke.typecho4j.jfinal.model.Meta;
import com.guxingke.typecho4j.widget.Widget;
import com.guxingke.typecho4j.widget.WidgetProvider;
import com.jfinal.core.Controller;

/**
 * 当前状态统计组件，为默认后台首页提供数据
 * 
 * @author guxingke
 * 
 */
public class StatWidget extends Widget implements WidgetProvider {
	private Long publishedPostsNum;
	private Long waitingPostsNum;
	private Long draftPostsNum;

	private Long publishedPagesNum;
	private Long draftPagesNum;

	private Long publishedCommentsNum;
	private Long waitingCommentsNum;
	private Long spamCommentsNum;

	private Long categoriesNum;

	@Override
	public boolean init() {
		initLogger();
		initProp();
		return true;
	}

	private void initProp() {
		publishedPostsNum = Content.dao.getPublishedPostsNum();
		waitingPostsNum = Content.dao.getWaitingPostsNum();
		draftPostsNum = Content.dao.getDraftPostsNum();

		publishedPagesNum = Content.dao.getPublishedPagesNum();
		draftPagesNum = Content.dao.getDraftPagesNum();

		publishedCommentsNum = Comment.dao.getPublishedCommentsNum();
		waitingCommentsNum = Comment.dao.getWaitingCommentsNum();
		spamCommentsNum = Comment.dao.getSpamCommentsNum();

		categoriesNum = Meta.dao.getCategoriesNum();
	}

	@Override
	public void excute(Controller controller) throws Typecho4jException {
		controller.setAttr("stat", this);
	}

	@Override
	public void refresh() {
		initProp();
	}

	public Long getPublishedPostsNum() {
		return publishedPostsNum;
	}

	public Long getWaitingPostsNum() {
		return waitingPostsNum;
	}

	public Long getDraftPostsNum() {
		return draftPostsNum;
	}

	public Long getPublishedPagesNum() {
		return publishedPagesNum;
	}

	public Long getDraftPagesNum() {
		return draftPagesNum;
	}

	public Long getPublishedCommentsNum() {
		return publishedCommentsNum;
	}

	public Long getWaitingCommentsNum() {
		return waitingCommentsNum;
	}

	public Long getSpamCommentsNum() {
		return spamCommentsNum;
	}

	public Long getCategoriesNum() {
		return categoriesNum;
	}
}
